<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <link rel="stylesheet" href="/static/admin/component/pear/css/pear.css"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        {#        form 表单#}
        <div class="layui-form" lay-filter="edit-filter">
            <div class="layui-form-item">
                <label class="layui-form-label">ID</label>
                <div class="layui-input-block layui-input-wrap">
                    <input type="tel" name="id" lay-verify="required"
                           autocomplete="off"
                           placeholder="请填写已存在的ID"
                           lay-reqtext="请填写ID" lay-affix="clear"
                           class="layui-input"
{#                           disabled#}
                           style="color: gray"
                    >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分类名</label>
                <div class="layui-input-block layui-input-wrap">
                    <input type="tel" name="name" lay-verify="required" autocomplete="off"
                           lay-reqtext="请填写分类名" lay-affix="clear" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="submit-cate">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/admin/component/layui/layui.js"></script>
<script src="/static/admin/component/pear/pear.js"></script>
<script src="/static/js/main.js"></script>
<script src="/static/js/api.js"></script>
<script>
  layui.use(function() {
    let layer = layui.layer;
    let table = layui.table;
    let form = layui.form;
    let $ = layui.jquery;
    let common = layui.common;

    let sp = new URLSearchParams(location.search);
    let cid = sp.get('cid');
    // 请求接口获取数据
    api_get(`/api/v1/cate/${cid}`).then(function(ret) {
      console.log(ret);
      if (!ret.code) {
        // 请求成功
        {#layer.msg(ret.message, {icon: 1});#}
        form.val('edit-filter', ret.data);
      } else {
        layer.msg(ret.message, {icon: 2});
      }
    });
    // 点击进行修改
    form.on('submit(submit-cate)', function(data) {
      let field = data.field;
      api_put(`/api/v1/cate/${data.field.id}`, field).then(function(ret) {
        if (!ret.code) {
          // 请求成功
          layer.msg(ret.message, {icon: 1});
          setTimeout(function() {
            parent.layer.closeAll('iframe');
            parent.refresh();
          }, 1500);
        } else {
          layer.msg(ret.message, {icon: 2});
        }
      });
      return false;
    });
  });
</script>
</body>
</html>
